<?php
$tb=array("drug","user","history","drug_history","hospital");
$tbn=0;
$table=$tb[$tbn];
function C($a){
	include "db2.php";
	return $db[$a];
}
$my_con=mysql_connect(C('DB_HOST').":".C('DB_PORT'),C('DB_USER'),C('DB_PWD'));
if(!$my_con){
		die('无法连接'.mysql_error());
	}
mysql_select_db(C('DB_NAME'),$my_con);
//取得表字段名
$query="SELECT * from ".C('DB_PREFIX').$table;
mysql_query("SET NAMES 'UTF8'");
$result=mysql_query($query,$my_con);
$arr="";
for($i=1;$i<mysql_num_fields($result);$i++){
	$ziduan=mysql_field_name($result,$i);
	$arr[$i]=$ziduan;
}
//将取得的字段名数组以,拼接为字符串
$zichuan=implode(",",$arr);
echo $zichuan."<br/>";
//建立初始数据
$contactPhone=13800138000;
$num=0;
require "n.php";

foreach($drugname as $contact) {
	$drug_name="'".$drugname[$num]."'";
	//药品价格
	$drug_price=rand(1,100).".".rand(001,999);

	//药品性状
	$drugtemper=array('处方类药','非处方药','医嘱监督','孕妇禁服','小儿慎重','未成人服用');
	$count=count($drugtemper);
	$drug_temper="'".$drugtemper[rand(0,$count-1)]."'";

	//药品计量
	$drugunit=array('支','片','板','瓶','管','桶','罐','包');
	$count=count($drugunit);
	$drug_unit="'".$drugunit[rand(0,$count-1)]."'";
	
	//echo $drug_name[$num]."  ".$drug_price."  ".$drug_temper."  ".$drug_unit."<br/>";

	$exec="insert into ".C("DB_PREFIX").$table." (".$zichuan.") values (".$drug_name.",".$drug_price.",".$drug_temper.",".$drug_unit.");";
	echo $exec."<br/>";
	mysql_query($exec,$my_con);
	if($erro=mysql_error()) echo $num." 次错误！！".$erro."<br/>";
	else echo $num . '次成功<br/>';
	
	$num=$num+1;
	$sumnum=$num;
	
}
echo '总共录入'.$sumnum.'条数据';
mysql_close($my_con);

?>